package com.basic.business.print.service.impl;

import com.basic.common.constant.CacheConstants;
import com.basic.common.core.redis.RedisCacheUtils;
import org.springframework.stereotype.Service;
import com.basic.common.core.service.impl.BaseServiceImpl;
import com.basic.business.print.domain.TOrdersPrint;
import com.basic.business.print.service.ITOrdersPrintService;
import com.basic.business.print.mapper.TOrdersPrintMapper;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
 * 业务-订单印刷品Service业务层处理
 *
 * @author zhaoxy_jn@163.com
 */
@Service
public class TOrdersPrintServiceImpl extends BaseServiceImpl<TOrdersPrintMapper,TOrdersPrint> implements ITOrdersPrintService {
    @Resource
    private TOrdersPrintMapper tOrdersPrintMapper;

    /**
     * 项目启动时，初始化印刷品编码缓存
     */
    @PostConstruct
    public void init(){
        resetPrintCache();
    }

    @Override
    public List<TOrdersPrint> getDoesIsExist(String printCode,String updateRowId) {
        return tOrdersPrintMapper.getDoesIsExist(printCode,updateRowId);
    }

    @Override
    public int updateStatusByIds(String[] ids, String status) {
        return tOrdersPrintMapper.updateStatusByIds(ids,status);
    }

    @Override
    public List<String> getNormalPrintCode() {
        return tOrdersPrintMapper.getNormalPrintCode();
    }

    /**
     * 重置印刷品缓存
     */
    @Override
    public void resetPrintCache(){
        // 清空缓存
        RedisCacheUtils.clearCache(CacheConstants.PRINTS_REDIS_KEY + "*");
        // 加载缓存
        RedisCacheUtils.setCacheObject(CacheConstants.PRINTS_REDIS_KEY, getNormalPrintCode());
    }
}
